package org.nfIt.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.nfIt.entity.User;

/**
 * ClossName:UserMapper
 * Pakage:org.nfIt.mapper
 * Description
 *
 * @Author L
 * @Create 2024/6/3 20:37
 * @Version 2023.1.3
 */
@Mapper
public interface UserMapper {

    /**
     * 查询用户名
     * @param username 用户名
     */
    @Select("select * from user where username = #{username}")
    User findByUsername(String username);

    /**
     * 根据usernaem and password注册账号
     * @param userName 用户名
     * @param password 密码
     */
    @Select("insert into user(username,password,create_time,update_time) values (#{username},#{password},now(),now()) ")
    void regUserNameAndPassword(@Param("username") String userName,@Param("password") String password);


    /**
     * 修改user
     * @param user 用户
     */
    @Update("update user set nickname=#{nickname},email=#{email},update_time=#{updateTime} where id=#{id}")
    void update(User user);

    /**
     * 更新头像
     * @param avatarUrl 头像地址
     */
    @Update("update user set user_pic=#{userPic},update_time=now() where id=#{id}")
    void updateAvatar(@Param("userPic") String avatarUrl,@Param("id") Integer id);

    /**
     * 更新密码
     * @param password 密码
     * @param id id
     */
    @Update("update user set password=#{password},update_time=now() where id=#{id}")
    void updatePwd(@Param("password") String password,@Param("id") Integer id);
}
